-- Copyright (c) 2024 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at:
--          http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.
local validate = require 'mc.validate'
local utils = require 'mc.utils'
local mdb = require 'mc.mdb'

local ComponentIntegrity = {}

---@class ComponentIntegrity.LastUpdated
---@field LastUpdated integer
local TLastUpdated = {}
TLastUpdated.__index = TLastUpdated
TLastUpdated.group = {}

local function TLastUpdated_from_obj(obj)
    return setmetatable(obj, TLastUpdated)
end

function TLastUpdated.new(LastUpdated)
    return TLastUpdated_from_obj({LastUpdated = LastUpdated})
end
---@param obj ComponentIntegrity.LastUpdated
function TLastUpdated:init_from_obj(obj)
    self.LastUpdated = obj.LastUpdated
end

function TLastUpdated:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TLastUpdated.group)
end

TLastUpdated.from_obj = TLastUpdated_from_obj

TLastUpdated.proto_property = {'LastUpdated'}

TLastUpdated.default = {0}

TLastUpdated.struct = {{name = 'LastUpdated', is_array = false, struct = nil}}

function TLastUpdated:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    validate.Optional(prefix .. 'LastUpdated', self.LastUpdated, 'uint64', true, errs, need_convert)

    TLastUpdated:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TLastUpdated.proto_property, errs, need_convert)
    return self
end

function TLastUpdated:unpack(_)
    return self.LastUpdated
end

ComponentIntegrity.LastUpdated = TLastUpdated

---@class ComponentIntegrity.Version
---@field Version string
local TVersion = {}
TVersion.__index = TVersion
TVersion.group = {}

local function TVersion_from_obj(obj)
    return setmetatable(obj, TVersion)
end

function TVersion.new(Version)
    return TVersion_from_obj({Version = Version})
end
---@param obj ComponentIntegrity.Version
function TVersion:init_from_obj(obj)
    self.Version = obj.Version
end

function TVersion:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TVersion.group)
end

TVersion.from_obj = TVersion_from_obj

TVersion.proto_property = {'Version'}

TVersion.default = {''}

TVersion.struct = {{name = 'Version', is_array = false, struct = nil}}

function TVersion:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    validate.Optional(prefix .. 'Version', self.Version, 'string', true, errs, need_convert)

    TVersion:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TVersion.proto_property, errs, need_convert)
    return self
end

function TVersion:unpack(_)
    return self.Version
end

ComponentIntegrity.Version = TVersion

---@class ComponentIntegrity.Type
---@field Type string
local TType = {}
TType.__index = TType
TType.group = {}

local function TType_from_obj(obj)
    return setmetatable(obj, TType)
end

function TType.new(Type)
    return TType_from_obj({Type = Type})
end
---@param obj ComponentIntegrity.Type
function TType:init_from_obj(obj)
    self.Type = obj.Type
end

function TType:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TType.group)
end

TType.from_obj = TType_from_obj

TType.proto_property = {'Type'}

TType.default = {''}

TType.struct = {{name = 'Type', is_array = false, struct = nil}}

function TType:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    validate.Optional(prefix .. 'Type', self.Type, 'string', true, errs, need_convert)

    if self.Type ~= nil then
        validate.Enum(prefix .. 'Type', self.Type, '', {'SPDM', 'TPM'}, errs, need_convert)
    end

    TType:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TType.proto_property, errs, need_convert)
    return self
end

function TType:unpack(_)
    return self.Type
end

ComponentIntegrity.Type = TType

ComponentIntegrity.interface = mdb.register_interface('bmc.kepler.RoT.ComponentIntegrity', {
    Type = {'s', {}, true, nil, false},
    Version = {'s', {}, true, nil, false},
    LastUpdated = {'t', {}, true, nil, false}
}, {}, {})

return ComponentIntegrity
